﻿using System;
using log4net;
using log4net.Core;
using ILogger = GeneralDFS.Interface.Logger.ILogger;

namespace GeneralDFS.Common.Logger
{
    public class Log4NetLogger:ILogger
    { 
        private ILog Logger;

        public Log4NetLogger()
        {
            Logger = LogManager.GetLogger("General_Disturbed_File_System");
        }
        #region ILogger Members

        public string Name { get; private set; }

        public void LogError(Exception e)
        {
            if (Logger != null)
            {
                Logger.Error(e);
            }
        }

        public void LogError(string title, Exception e)
        {
            if (Logger != null)
            {
                Logger.Error(title, e);
            }
        }

        public void LogError(string message)
        {
            if (Logger != null)
            {
                Logger.Error(message);
            }
        }

        public void LogDebug(string message)
        {
            if (Logger != null)
            {
                Logger.Debug(message);
            }
        }


        public virtual void LogInfo(string message)
        {
            if (Logger != null)
            {
                Logger.Info(message);
            }
        }

        public virtual void LogPerf(string message)
        {
            if (Logger != null)
            {
                Logger.Logger.Log(new LoggingEvent(new LoggingEventData
                {
                    LoggerName = Name,
                    Message = message,
                    Level = Level.Trace,
                    TimeStamp = DateTime.Now,
                    Domain = AppDomain.CurrentDomain.FriendlyName
                }));
            }
        }

        public void LogInfo(string format, params object[] args)
        {
            if (Logger != null)
            {
                Logger.InfoFormat(format,args);
            }
        }

        public void LogDebug(string format, params object[] args)
        {
            if (Logger != null)
            {
                Logger.DebugFormat(format, args);
            }
        }

        #endregion
    }
}
